<%@ include file="/common/taglibs.jsp"%>

<script type="text/javascript">var batchApproveTransferMessage ="<fmt:message key="batchApproveTransfer.message"/>";</script>

<head>
    <title><fmt:message key="loanRequestList.title"/></title>
    <meta name="menu" content="LoanRequestListMenu"/>
</head>

<security:authorize ifAnyGranted="ROLE_DEALER_USER">
    <c:set var="availableRequestStatus" value="${availableDealerRequestStatus}"/>
</security:authorize>
<security:authorize ifNotGranted="ROLE_DEALER_ADMIN,ROLE_DEALER_USER">
    <c:set var="availableRequestStatus" value="${availableLoanRequestStatus}"/>
</security:authorize>

<c:if test="{'$'}{not empty searchError}">
    <div class="alert alert-danger alert-dismissable">
        <a href="#" data-dismiss="alert" class="close">&times;</a>
        <c:out value="{'$'}{searchError}"/>
    </div>
</c:if>

<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        <fmt:message key="loanRequestList.heading"/>
        <small><p><fmt:message key="loanRequestList.message"/></p></small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i><fmt:message key="loanRequestList.heading"/></a></li>
        <li class="active"> <fmt:message key="loanRequestList.heading"/></li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <%@ include file="/common/messages.jsp" %>
            <div class="box">
                
                <div class="box-body">
                    <form action="batchApproveTransfer" method="get">
                        <display:table name="loanRequestList" class="table table-bordered table-hover" requestURI="" id="loanRequestList" export="false" pagesize="25">
                            <display:column titleKey="button.select" sortable="false" style="width: 3%;">
                                <input type="checkbox" name="selectedIds" value="<c:out value="${loanRequestList.id}"/>"/>
                            </display:column>
                            <display:column property="number" sortable="true" href="loanRequestform" media="html" style="width: 8%;"
                                            paramId="reqId" paramProperty="id" titleKey="loanRequest.number"/>
                            <display:column class="requestId" property="id" media="csv excel xml pdf" titleKey="loanRequest.id"/>
                            <display:column property="requestPerson.name" sortable="true" titleKey="loanRequest.requestUser" style="width: 7%;"/>
                            <display:column property="dealer.name" sortable="true" titleKey="loanRequest.dealer" style="width: 8%;"/>
                            <display:column property="dealerUser.username" sortable="true" titleKey="loanRequest.dealerUser" style="width: 8%;"/>
                            <display:column sortable="true" titleKey="loanRequest.idType" style="width: 8%;"><fmt:message key="ID_TYPE_${loanRequestList.requestPerson.idType}"/></display:column>
                            <display:column property="requestPerson.idNo" sortable="true" titleKey="loanRequest.idNo" style="width: 9%;"/>
                            <display:column sortable="true" titleKey="loanRequest.status" style="width: 8%;"><fmt:message key="REQUEST_STATUS_${loanRequestList.status}"/></display:column>
                            <security:authorize ifNotGranted="ROLE_DEALER_USER">
                                <display:column sortable="true" titleKey="loanRequest.phase" style="width: 8%;"><fmt:message key="PHASE_${loanRequestList.phase}"/></display:column>
                            </security:authorize>
                            <%--<display:column property="auditUser.username" sortable="true" titleKey="loanRequest.auditUser" style="width: 7%;"/>--%>
                            <display:column sortProperty="requestDate" sortable="true" titleKey="loanRequest.requestDate" style="width: 7%;">
                                <fmt:formatDate value="${loanRequestList.requestDate}" pattern="${datePattern}"/>
                            </display:column>
                            <%--<display:column sortable="true" titleKey="loanRequest.feedbackType" style="width: 9%;"><fmt:message key="FEEDBACK_STATUS_${loanRequestList.feedbackType}"/></display:column>--%>
                            <display:column titleKey="loanRequest.changeApprove" style="width: 9%;" media="html">
                                <input type="checkbox" disabled="disabled" <c:if test="${loanRequestList.auditCode == 'changeApprove'}">checked="checked"</c:if>/>
                            </display:column>
                            <security:authorize ifNotGranted="ROLE_DEALER_USER">
                                <display:column titleKey="loanRequest.sendBack" style="width: 5%;" media="html">
                                    <input type="checkbox" disabled="disabled" <c:if test="${loanRequestList.sendback}">checked="checked"</c:if>/>
                                </display:column>
                            </security:authorize>

                            <display:column sortable="false" titleKey="loanRequestDetail.actionTitle">
                                <security:authorize ifAnyGranted="ROLE_Bond_USER">
                                    <c:if test="${loanRequestList.phase == 'loan_approved' and loanRequestList.prepayment == null}">
                                        <a class="btn btn-primary btn-xs" href='/prepaymentform?reqId=${loanRequestList.id}'><fmt:message key="button.prepayment"></fmt:message></a>
                                    </c:if>
                                </security:authorize>
                            </display:column>

                            <display:setProperty name="paging.banner.item_name"><fmt:message key="loanRequestList.loanRequest"/></display:setProperty>
                            <display:setProperty name="paging.banner.items_name"><fmt:message key="loanRequestList.loanRequests"/></display:setProperty>

                            <display:setProperty name="export.excel.filename"><fmt:message key="loanRequestList.title"/>.xls</display:setProperty>
                            <display:setProperty name="export.csv.filename"><fmt:message key="loanRequestList.title"/>.csv</display:setProperty>
                            <display:setProperty name="export.pdf.filename"><fmt:message key="loanRequestList.title"/>.pdf</display:setProperty>
                        </display:table>
                        <button type="submit" class="btn btn-primary" id="batchApproveTransfer" name="batchAudit" onclick="return checkBatch();">
                            <i class="icon-ok icon-white"></i> <fmt:message key="loanRequestDetail.action.batchApproveTransfer"/>
                        </button>
                    </form>
                </div><!-- /.box-body -->

            </div><!-- /.box -->
        </div>
    </div>

</section><!-- /.content -->

<c:set var="scripts" scope="request">
    <script type='text/javascript' src="<c:url value='/dwr/interface/UserManager.js'/>"></script>
    <script type='text/javascript' src="<c:url value='/dwr/engine.js'/>"></script>
    <script type='text/javascript' src="<c:url value='/dwr/util.js'/>"></script>
<script type="text/javascript">
    $(function () {
        $('.datepicker').datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: "mm/dd/yy"
        });
        $('#loanRequestList').dataTable({
            "language": {
                "url": "//cdn.datatables.net/plug-ins/1.10.7/i18n/Chinese.json"
            },
            "bPaginate": false,
            "bLengthChange": false,
            "bFilter": false,
            "bSort": true,
            "bInfo": false,
            "bAutoWidth": true
        });

        function checkBatch() {
            var selectedIds = $("input[name='selectedIds']:checked").val();
            if (!selectedIds || selectedIds.length == 0) {
                alert(batchexportMessage);
                return false;
            } else {
                return true;
            }
        }

    });



</script>
</c:set>
